package Lamport;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class NodeGenerator {

	
	public String owner;
	
	public NodeGenerator(){}
	
	public NodeGenerator(String owner, int pid) {
        this.owner = owner;
     
	}
	
	/** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path,
                                               String description) {
        java.net.URL imgURL = GUI.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL, description);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }    
    
    /**
     * Function - getHostName
     * @return String - Hostname of the process
     */
    public String getHostName() {
    	return owner;
    }
    
    /**
     * Function - createGreenIcon
     * @param hostname - String - The host name of the process
     * @return JLabel with displayed host name and green ImageIcon
     */
    public JLabel createGreenIcon(String hostname) {
    	JLabel myGreenResource;
    	ImageIcon greenCircle = createImageIcon("image/green.png","Green Circle");
    	myGreenResource = new JLabel(hostname, greenCircle, JLabel.CENTER);
        myGreenResource.setVerticalTextPosition(JLabel.BOTTOM);
        myGreenResource.setHorizontalTextPosition(JLabel.CENTER);
        myGreenResource.setToolTipText(hostname+" is controlling the resource");
        return myGreenResource;
    }
    
    /**
     * Function - createRedIcon
     * @param hostname - String - The host name of the process
     * @return JLabel with displayed host name and red ImageIcon
     */
    public JLabel createRedIcon(String hostname) {
    	JLabel myRedResource;
    	ImageIcon redCircle = createImageIcon("image/red.png", "Red Circle");
    	myRedResource = new JLabel(hostname, redCircle, JLabel.CENTER);
    	myRedResource.setVerticalTextPosition(JLabel.BOTTOM);
        myRedResource.setHorizontalTextPosition(JLabel.CENTER);
        myRedResource.setToolTipText(hostname+" is NOT controlling the resource");
    	return myRedResource;
    }
}
